$(document).ready(function(){
    // '<p class="products_desc"> 对接成功<em>881</em>项需求 </p>'
    var userName = window.localStorage.getItem("admin");
    var regionArr = ["碑林区","莲湖区","灞桥区","雁塔区","阎良区","未央区","新城区","长安区","临潼区"];
    $(".fiUsername").html(userName);
    function queryEnterprise (){
        $(".products-list").remove();
        $(".card-body--padding").append('<div class="products-list"></div>');
        $.ajax({
            type : "POST",
            url:"http://59.110.114.107:8888/admin/enterpriseManage/check",
            // data:{
            //     pageNum:1,
            //     pageSize:10000
            // },
            success:function(result){
                // '                                            <button class="products-btn" id="edit">编辑</button>' +
                var data=result.data;
                if(data){
                    var data1=data.map(function (item,index) {
                        return '<dl style="padding-top: 0px;" class="products-item insurance three six twelve thirty-six credit unconnect unplicy -ten">' +
                            '                            <dt>' +item.enterpriseName+
                            '                            </dt>' +
                            '                            <dd>' +
                            '                                <div class="products-info">' +
                            '                                    <div class="products-type">' +
                            '                                        <span class="products-type_item">' +
                            '                                            <span>统一社会信用代码：</span><em>'+item.socialCode+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>注册资金：</span><em>'+item.registeredCaptial+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>区域：</span><em>'+regionArr[item.region]+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>法人姓名：</span><em>'+item.ownerName+'</em>' +
                            '                                        </span><span class="products-type_item">' +
                            '<span>法人电话：</span><em>'+item.ownerPhone+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>成立时间：</span><em>'+item.establishTime.slice(0,10)+'</em>' +
                            '                                        </span>' +
                            '                                    </div>' +
                            '                                    <div class="products-action">' +
                            '                                        <p class="btn-wrap">' +
                            '                                            <button class="products-btn products-btn--red apply apply delete" id="'+index+'">删除</button>' +
                            '                                        </p>' +
                            '                                        <p class="proecuts-success" style="visibility: hidden">' +
                            '                                            <span class="desc">成功率</span>' +
                            '                                            <span class="score-bar">' +
                            '<span class="score" style="width: 0%;"></span>' +
                            '</span>' +
                            '                                        </p>' +
                            '                                    </div>' +
                            '                                </div>' +
                            '                            </dd>' +
                            '                        </dl>'
                    })
                    $(".products-list").append(data1);
                    var btn=$(".delete");
                    for(var i=0;i<btn.length;i++){
                        btn[i].onclick=function (e) {
                            console.log(e.target);
                            $.ajax({
                                type:'POST',
                                url:'http://59.110.114.107:8888/admin/enterpriseManage/delete',
                                data:{
                                    userName:data[e.target.id].socialCode
                                },
                                success:function (result) {
                                    if(result.meta.code=='4002'){
                                        alert("删除成功！")
                                        queryEnterprise();
                                    }else{
                                        alert("删除失败！")
                                    }
                                },
                                error:function(){
                                    alert("错误");
                                }
                            })
                        }
                    }
                }


            },
            error:function(){
                alert("错误");
            }
        });
    }
    queryEnterprise();
    //-----------------获取企业列表--------------------------------
    $("#queryEnterprise").click(function () {
        queryEnterprise();
    })
    //-----------------获取金融列表--------------------------------
    $("#queryBank").click(function () {
        $(".products-list").remove();
        $(".card-body--padding").append('<div class="products-list"></div>');
        $.ajax({
            type : "POST",
            url:"http://59.110.114.107:8888/admin/bankManage/check",
            // data:{
            //     pageNum:1,
            //     pageSize:10000
            // },
            success:function(result){
                // '                                            <button class="products-btn" id="edit">编辑</button>' +
                var data=result.data;
                if(data){
                    var data1=data.map(function (item,index) {
                        if(item.description==null){
                            item.description='';
                        }
                        return '<dl style="padding-top: 0px;" class="products-item insurance three six twelve thirty-six credit unconnect unplicy -ten">' +
                            '                            <dt>' +item.bankName+
                            '                            </dt>' +
                            '                            <dd>' +
                            '                                <div class="products-info">' +
                            '                                    <div class="products-type">' +
                            '                                        <span class="products-type_item">' +
                            '                                            <span>用户名：</span><em>'+item.fkUserName+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>区域：</span><em>'+regionArr[item.regin]+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>街道：</span><em>'+item.street+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>联系人姓名：</span><em>'+item.contactName+'</em>' +
                            '                                        </span><span class="products-type_item">' +
                            '<span>联系人电话：</span><em>'+item.contactPhone+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>描述：</span><em>'+item.description+'</em>' +
                            '                                        </span>' +
                            '                                    </div>' +
                            '                                    <div class="products-action">' +
                            '                                        <p class="btn-wrap">' +
                            '                                            <button class="products-btn products-btn--red apply apply btn-delete" id="'+index+'">删除</button>' +
                            '                                        </p>' +
                            '                                        <p class="proecuts-success" style="visibility: hidden">' +
                            '                                            <span class="desc">成功率</span>' +
                            '                                            <span class="score-bar">' +
                            '<span class="score" style="width: 0%;"></span>' +
                            '</span>' +
                            '                                        </p>' +
                            '                                    </div>' +
                            '                                </div>' +
                            '                            </dd>' +
                            '                        </dl>'
                    })
                    $(".products-list").append(data1);
                    var btn=$(".btn-delete");
                    console.log(123)
                    console.log(btn);
                    for(var i=0;i<btn.length;i++){
                        btn[i].onclick=function (e) {
                            $.ajax({
                                type:'POST',
                                url:'http://59.110.114.107:8888/admin/bankManage/delete',
                                data:{
                                    userName:data[e.target.id].fkUserName
                                },
                                success:function (result) {
                                    if(result.meta.code=='4002'){
                                        alert("删除成功！")
                                        $("#queryBank").click();
                                    }else{
                                        alert("删除失败！")
                                    }
                                },
                                error:function(){
                                    alert("错误");
                                }
                            })
                        }
                    }
                }

            },
            error:function(){
                alert("错误");
            }
        });
    })

    //-----------------获取政府列表--------------------------------
    $("#queryGovernment").click(function () {
        $(".products-list").remove();
        $(".card-body--padding").append('<div class="products-list"></div>');
        $.ajax({
            type : "POST",
            url:"http://59.110.114.107:8888/admin/governmentManage/check",
            // data:{
            //     pageNum:1,
            //     pageSize:10000
            // },
            success:function(result){
                // '                                            <button class="products-btn" id="edit">编辑</button>' +
                var data=result.data;
                if(data){
                    var data1=data.map(function (item,index) {
                        return '<dl style="padding-top: 0px;" class="products-item insurance three six twelve thirty-six credit unconnect unplicy -ten">' +
                            '                            <dt>' +item.fkUserName+
                            '                            </dt>' +
                            '                            <dd>' +
                            '                                <div class="products-info">' +
                            '                                    <div class="products-type">' +
                            '                                        <span class="products-type_item">' +
                            '                                            <span>政府代码：</span><em>'+item.governmentCode+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>部门：</span><em>'+item.departmentName+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>负责人姓名：</span><em>'+item.principalName+'</em>' +
                            '                                        </span>' +
                            '                                        <span class="products-type_item">' +
                            '<span>负责人电话：</span><em>'+item.principalPhone+'</em>' +
                            '                                        </span>'+
                            '                                    </div>' +
                            '                                    <div class="products-action">' +
                            '                                        <p class="btn-wrap">' +
                            '                                            <button class="products-btn products-btn--red apply apply delete" id="'+index+'">删除</button>' +
                            '                                        </p>' +
                            '                                        <p class="proecuts-success" style="visibility: hidden">' +
                            '                                            <span class="desc">成功率</span>' +
                            '                                            <span class="score-bar">' +
                            '<span class="score" style="width: 0%;"></span>' +
                            '</span>' +
                            '                                        </p>' +
                            '                                    </div>' +
                            '                                </div>' +
                            '                            </dd>' +
                            '                        </dl>'
                    })
                    $(".products-list").append(data1);
                    var btn=$(".delete");
                    for(var i=0;i<btn.length;i++){
                        btn[i].onclick=function (e) {
                            $.ajax({
                                type:'POST',
                                url:'http://59.110.114.107:8888/admin/governmentManage/delete',
                                data:{
                                    userName:data[e.target.id].fkUserName
                                },
                                success:function (result) {
                                    if(result.meta.code=='4002'){
                                        alert("删除成功！")
                                        $("#queryGovernment").click();
                                    }else{
                                        alert("删除失败！")
                                    }
                                },
                                error:function(){
                                    alert("错误");
                                }
                            })
                        }
                    }
                }

            },
            error:function(){
                alert("错误");
            }
        });
    })

    //---------------------退出
    $(".exit").click(function(){
        alert("退出登录！");
        window.localStorage.clear();
        window.location.href = "index.html";
    });
});